﻿var ajaxApp = {};


//Recursive timeout
function showAlert(time) {
    alert('Seconds: ' + time / 1000);
    time += time;
    setTimeout('showAlert(' + time + ')', time);
}

var handle = setTimeout('showAlert(1000)', 1000);




ajaxApp.getAllShips = function (callback) {
    var harryPotterStuff = {};

    var request = new XMLHttpRequest();
    request.open('GET', 'https://tmfahall.firebaseio.com/.json', true);
    request.onload = function () {
        harryPotterStuff = JSON.parse(this.response);

        if (callback && typeof (callback) == 'function') {
            callback(harryPotterStuff);
        }
    }

    //Send the request
    request.send();
}
var myCallBack = function (harryPotterStuff) {
    for (var name in harryPotterStuff) {
        alert(harryPotterStuff[name].name);
    }
}

ajaxApp.getAllShips(myCallBack);